#ifndef _BINARY_TREE_H_
#define _BINARY_TREE_H_

#include "util.h"
typedef int (*CompareFunc)(const void *, const void*);
typedef struct tagBNode
{
	void *data;
	struct tagBNode *p;
	struct tagBNode *left;
	struct tagBNode *right;
} BNode, *pBNode;

typedef struct tagBTree
{
	pBNode root;
	CompareFunc Compare;
	size_t nodeCount;
} BTree, *pBTree;

pBTree CreateBTree(CompareFunc);
pBNode InsertBNode(pBTree tree, void *data);
pBNode SearchBTree(pBTree tree, void *data);
void ReleaseBTree(pBTree tree);
pBNode *SortBTree(pBTree tree, int desc, int*);
void TraverseBNode(pBNode node, int desc, void (*Action)(pBNode, void *));
#endif